<template>
  <base-modal
    :show.sync="visible"
    width="500px"
    class="editor-column-dialog"
    @closed="onClose('form')"
  >
    <div slot="title">
      <span class="el-dialog__title">{{$t('task.setting.components.editFields')}}</span>
    </div>
    <div class="base-modal-content">
      <el-checkbox 
        v-model="field.isHidden" 
        :true-label="0" 
        :false-label="1"
        v-for="field in fieldsList" 
        :key="field.fieldId"
        :disabled="field.fieldName=='name' || field.fieldName=='preNum' || field.fieldName=='total'"
      >{{field.displayName}}</el-checkbox>
    </div>
    <div slot="footer" class="dialog-footer">
      <el-button @click="onClose">{{$t('common.base.cancel')}}</el-button>
      <el-button type="primary" @click="onSubmit">{{$t('common.base.makeSure')}}</el-button>
    </div>
  </base-modal>
</template>
<script>
/* util */
import _ from 'lodash';
export default {
  name: 'editor-column-dialog',
  data() {
    return {
      fields:[],
      placeholder:'',
      visible: false,
      isNull:0
    };
  },
  computed: {
    // 编辑字段显示 单价显示则小计默认选中
    fieldsList() {
      let isShow = this.fields.some(item => item.fieldName == 'salePrice' && item.isHidden == 0);
      if(isShow){
        this.fields.forEach(item => {
          if(item.fieldName == 'total'){
            item.isHidden = 0;
          }
        });
      }else{
        this.fields.forEach(item => {
          if(item.fieldName == 'total'){
            item.isHidden = 1;
          }
        });
      }
       
      return this.fields

    },
  },
  methods: {
    openDialog() {
      this.visible = true;
      
    },
    onClose() {
      this.visible = false;

    },
    onSubmit() {
      this.onClose();
      this.$emit('onSave', this.fields)
    }
  },
};
</script>
<style lang="scss">
.editor-column-dialog {
  .base-modal-header {
    display: flex;
    justify-content: space-between;
    .el-dialog__title {
      font-size: 18px;
    }
    .el-tooltip {
      color: #999;
    }
  }
  .base-modal-body {
    padding: 20px;
    .fields-name{
      margin-bottom: 19.5px;
    }
  }
}
</style>